//
//  LoginVC.m
//  SchoolCircle
//
//  Created by 战立军 on 16/5/27.
//  Copyright © 2016年 战立军. All rights reserved.
//

#import "LoginVC.h"
#import "RegistVC.h"
#import "ForgetpwdVC.h"
#import "MainVCViewController.h"


#import "TPKeyboardAvoidingScrollView.h"

#define WH 30

@interface LoginVC ()
{
    UIImageView *_bgImage;
    UITextField *_username;
    UITextField *_userpwe;
    
    UIButton *_loginBtn;
    UIButton *_regiseBtn;
    UIButton *_forgetBtn;
    
    TPKeyboardAvoidingScrollView *_scrollView;
}
@end

@implementation LoginVC

- (void)viewDidLoad {
    [super viewDidLoad];
    _scrollView = [[TPKeyboardAvoidingScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIUTils getWindowWidth], [UIUTils getWindowHeight])];
    _scrollView.backgroundColor = [UIColor whiteColor];
    // 设置内容大小
    _scrollView.contentSize = CGSizeMake([UIUTils getWindowWidth], [UIUTils getWindowHeight]);
    // 提示用户,Indicators flash
    [_scrollView flashScrollIndicators];
    [self.view addSubview:_scrollView];
    [self addContantView];
    
    [self setNavgiton];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/**
 *  添加视图
 */
- (void)addContantView
{
    _bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [UIUTils getWindowWidth], [UIUTils getWindowHeight])];
    _bgImage.alpha = 0.5;
    _bgImage.image = [UIImage imageNamed:@"bgImage"];
    _bgImage.userInteractionEnabled = YES;
    [_scrollView addSubview:_bgImage];
    
    
    _loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _loginBtn.frame = CGRectMake(WH, self.view.center.y+30, [UIUTils getWindowWidth]-WH*2, 50);
    _loginBtn.layer.cornerRadius = 10;
    _loginBtn.backgroundColor = [UIColor redColor];
    [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
    [_loginBtn addTarget:self action:@selector(loginButtonpress) forControlEvents:UIControlEventTouchUpInside];
    [_scrollView addSubview:_loginBtn];
    
    _userpwe = [[UITextField alloc] initWithFrame:CGRectMake(WH, _loginBtn.frame.origin.y-20-40, [UIUTils getWindowWidth]-WH*2, 40)];
//    _userpwe.backgroundColor = [UIColor yellowColor];
    _userpwe.borderStyle = UITextBorderStyleRoundedRect;
    _userpwe.backgroundColor = Color(246, 246, 246);
    _userpwe.placeholder = @"密码";
    [_scrollView addSubview:_userpwe];
    
    _username = [[UITextField alloc] initWithFrame:CGRectMake(WH, _userpwe.frame.origin.y-20-40, [UIUTils getWindowWidth]-WH*2, 40)];
    _username.borderStyle = UITextBorderStyleRoundedRect;
    _username.backgroundColor = Color(246, 246, 246);
    _username.placeholder = @"用户名";
    [_scrollView addSubview:_username];
    
    
    _regiseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _regiseBtn.frame = CGRectMake(WH, CGRectGetMaxY(_loginBtn.frame)+20, [UIUTils getWindowWidth]/2-WH, 40);
    [_regiseBtn setTitle:@"注册账号" forState:UIControlStateNormal];
    [_regiseBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_regiseBtn addTarget:self action:@selector(registButtonpress) forControlEvents:UIControlEventTouchUpInside];
    [_regiseBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [_scrollView addSubview:_regiseBtn];
    
    _forgetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _forgetBtn.frame = CGRectMake(CGRectGetMaxX(_regiseBtn.frame), CGRectGetMaxY(_loginBtn.frame)+20, [UIUTils getWindowWidth]/2-WH, 40);
    [_forgetBtn setTitle:@"忘记密码？" forState:UIControlStateNormal];
    [_forgetBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_forgetBtn addTarget:self action:@selector(forgetpwdButtonPress) forControlEvents:UIControlEventTouchUpInside];
    [_forgetBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
    [_scrollView addSubview:_forgetBtn];
}


#pragma mark 其他功能区
/**
 *  设置导航栏
 */
- (void)setNavgiton
{
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"uitabr"]]];
    self.title = @"登录";
    // 设置导航默认标题的颜色及字体大小
    self.navigationController.navigationBar.titleTextAttributes = @{UITextAttributeTextColor: [UIColor whiteColor],
                                                                    UITextAttributeFont : [UIFont boldSystemFontOfSize:18]};
}

#pragma mark 主功能区
/**
 *  登录
 */
- (void)loginButtonpress
{
    NSLog(@"%s",__func__);
    
    [self presentViewController:[[MainVCViewController alloc] init] animated:YES completion:nil];
}

/**
 *  注册
 */
- (void)registButtonpress
{
      NSLog(@"%s",__func__);
    [self presentViewController:[[RegistVC alloc] init] animated:YES completion:nil];
//    [self.navigationController pushViewController:[[RegistVC alloc] init] animated:YES];
    
}
/**
 *  忘记密码
 */
- (void)forgetpwdButtonPress
{
    
      NSLog(@"%s",__func__);
    [self presentViewController:[[ForgetpwdVC alloc] init] animated:YES completion:nil];
}

@end
